﻿#include "AppDelegate.h"
#include "LogoScene.h"

using namespace cocos2d;

// 窗口的大小
static cocos2d::Size designResolutionSize = cocos2d::Size(480, 854);

AppDelegate::AppDelegate() 
{
}

AppDelegate::~AppDelegate() 
{
}

void AppDelegate::initGLContextAttrs()
{
    //set OpenGL context attributions,now can only set six attributions:
    //red,green,blue,alpha,depth,stencil
    GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};

    GLView::setGLContextAttrs(glContextAttrs);
}

static int register_all_packages()
{
    return 0; //flag for packages manager
}

bool AppDelegate::applicationDidFinishLaunching() 
{
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
		glview = GLViewImpl::createWithRect(
			"Edu_RW_RJ_2023", 
			Rect(0, 0, designResolutionSize.width*0.75f, designResolutionSize.height*0.75f));
#else
        glview = GLViewImpl::create("carrot");
#endif
        director->setOpenGLView(glview);
    }
    director->setDisplayStats(false);
    director->setAnimationInterval(1.0f / 60.0f);
    glview->setDesignResolutionSize(
		designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
	register_all_packages();
	    
    srand(time(nullptr));// 随机种子

	// 创建自动释放场景对象
    auto scene = LogoScene::create();
	// 类名 类对象 = new 类名();
	auto i = true;
    director->runWithScene(scene);

    return true;
}

void AppDelegate::applicationDidEnterBackground() 
{
    Director::getInstance()->stopAnimation();

    // if you use SimpleAudioEngine, it must be pause
    // SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}

void AppDelegate::applicationWillEnterForeground() 
{
    Director::getInstance()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    // SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}
